package com.ebarlas.fractal.compile.function;

import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;

import com.ebarlas.fractal.compile.CompilerUtils;
import com.ebarlas.fractal.compile.StackCommand;
import com.ebarlas.fractal.util.ArrayStack;
import com.ebarlas.fractal.util.Complex;

public class GreaterThanEquals implements StackCommand {
    
    private static final GreaterThanEquals INSTANCE = new GreaterThanEquals();
    
    private GreaterThanEquals() {}
    
    public static GreaterThanEquals getInstance() {
        return INSTANCE;
    }    
    
    public int consumed() {
        return 2;
    }
    
    public int produced() {
        return 1;
    }
    
    public void interpret(ArrayStack<Complex> stack) {
        Complex right = stack.pop();
        stack.push(Complex.greaterThanEquals(stack.pop(), right));
    }
    
    public void compileConstructor(ConstantPoolGen cp, InstructionList il, InstructionFactory factory) {}
    
    public void compileExecute(ConstantPoolGen cp, InstructionList il, InstructionFactory factory) {
        il.append(CompilerUtils.getComplexInvokeInst(factory, "greaterThanEquals", 2));
    }  
    
}
